Skip to content

Conversation

@mcintyre94
Copy link
Member

This PR adds a new instruction plan to create a mint. This combines the createAccount instruction from the system program, with the initializeMint2 instruction from the token program.

I've structured it to take input in a similar way to generated instructions.

I've also added test helpers for a transaction plan/executor, using the same behaviour as the existing test helpers.

Example:

const instructionPlan = getCreateMintInstructionPlan({
    payer: authority,
    newMint: mint,
    decimals: 2,
    mintAuthority: authority.address,
});

const transactionPlan = await transactionPlanner(instructionPlan);
await transactionPlanExecutor(transactionPlan);


// RPC `getMinimumBalanceForRentExemption` for 82 bytes
// Hardcoded to avoid requiring an RPC request each time
const minimumBalanceForMint = 1461600;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To flag this, I think it's wasteful/annoying to require you to pass Rpc<GetMinimumBalanceForRentExemption> API and re-calculate this every time, given this value doesn't change (without a server change).

Can change to do that though!

I added an optional minimumBalanceForMintOverride override in case you want to use this with a Solana network with different logic, or to account for a hypothetical change in future before the library is updated, but intended most usage to just not have to think about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's a great idea. IIRC we even discussed the possibility of adding a sync helper like that to Kit. Not sure where we landed on that though.

I also like the override parameter. What do you think of calling it mintBalance or mintLamports instead? I'm not a fan of "minimum balance" here because the created account will have this exact balance after the transaction. Also "override" might be redundant since it's optional.

Copy link
Member Author

@mcintyre94 mcintyre94 Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like mintLamports, and good to drop the override!
Edit: Went with mintAccountLamports

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Kit sync helper, my issue is anza-xyz/kit#777

I don't think we really discussed it but I still think this would be worth having. Feels like the risk of this changing frequently is very low.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. I have a feeling that Steven wanted to first figure out a way to offer slot-specific or feature-specific builds of Kit so that, if this was to change in the future, we could gracefully offer two version of the library with different values based on the current state of the cluster.

lorisleiva
lorisleiva previously approved these changes Nov 18, 2025
Copy link
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for that! I've made a few small comments.


// RPC `getMinimumBalanceForRentExemption` for 82 bytes
// Hardcoded to avoid requiring an RPC request each time
const minimumBalanceForMint = 1461600;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's a great idea. IIRC we even discussed the possibility of adding a sync helper like that to Kit. Not sure where we landed on that though.

I also like the override parameter. What do you think of calling it mintBalance or mintLamports instead? I'm not a fan of "minimum balance" here because the created account will have this exact balance after the transaction. Also "override" might be redundant since it's optional.

Comment on lines 50 to 51
export const createDefaultSolanaClient = (): Client => {
const rpc = createSolanaRpc('http://127.0.0.1:8899');
const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');
return { rpc, rpcSubscriptions };
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also happy to refactor this slightly in the tests so we can bake a sendAndConfirm function in the Client by accepting a feePayer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be good with that too, just wasn't sure if any tests are eg using multiple fee payers, or if we might want that kind of flexibility later. Either way I don't think the duplication is a concern in test helpers ATM.


// RPC `getMinimumBalanceForRentExemption` for 82 bytes, which is token mint size
// Hardcoded to avoid requiring an RPC request each time
const minimumBalanceForMint = 1461600;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: Since this is a constant, could we uppercase it so it's clear when reading the code that it's a static value.

Suggested change
const minimumBalanceForMint = 1461600;
const MINIMUM_BALANCE_FOR_MINT = 1461600;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants